﻿/*******************************************************************************************************************************************
Modification History:
********************************************************************************************************************************************
Date		Author		    Description
********************************************************************************************************************************************
05/07/2011	Brian Kuhn	    Created SubscriptionChangedEventArgs class
*******************************************************************************************************************************************/
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace Concise
{
    /// <summary>
    /// Provides data for the <see cref="IServiceBus.SubscriptionChanged"/> event.
    /// </summary>
    [DataContract()]
    public class SubscriptionChangedEventArgs : EventArgs
    {
        //=======================================================================================================
        //  Constructors
        //=======================================================================================================
        #region SubscriptionChangedEventArgs()
        /// <summary>
        /// Initializes a new instance of the <see cref="SubscriptionChangedEventArgs"/> class.
        /// </summary>
        protected SubscriptionChangedEventArgs() : base()
        {

        }
        #endregion

        #region SubscriptionChangedEventArgs(IEnumerable<Type> added, IEnumerable<Type> removed)
        /// <summary>
        /// Initializes a new instance of the <see cref="SubscriptionChangedEventArgs"/> class 
        /// using the message types that were affected by the change.
        /// </summary>
        /// <param name="added">The messages types that were added. Can be <see langword="null"/>.</param>
        /// <param name="removed">The messages types that were removed. Can be <see langword="null"/>.</param>
        public SubscriptionChangedEventArgs(IEnumerable<Type> added, IEnumerable<Type> removed) : this()
        {
            if (added != null)
            {
                foreach(var type in added)
                {
                    if(type != null)
                    {
                        this.Added.Add(type.AssemblyQualifiedName);
                    }
                }
            }

            if (removed != null)
            {
                foreach (var type in removed)
                {
                    if (type != null)
                    {
                        this.Removed.Add(type.AssemblyQualifiedName);
                    }
                }
            }
        }
        #endregion

        //=======================================================================================================
        //  Public Properties
        //=======================================================================================================
        #region Added
        /// <summary>
        /// Gets the assembly-qualified names of the messages types that were added.
        /// </summary>
        /// <value>
        /// A <see cref="List{String}"/> collection that contains the assembly-qualified names of the messages types that were added. 
        /// The default value is an <i>empty</i> collection.
        /// </value>
        [DataMember()]
        public List<string> Added
        {
            get
            {
                if (_eventArgsAdded == null)
                {
                    _eventArgsAdded = new List<string>();
                }
                return _eventArgsAdded;
            }
        }
        private List<string> _eventArgsAdded;
        #endregion

        #region Removed
        /// <summary>
        /// Gets the assembly-qualified names of the messages types that were removed.
        /// </summary>
        /// <value>
        /// A <see cref="List{String}"/> collection that contains the assembly-qualified names of the messages types that were removed. 
        /// The default value is an <i>empty</i> collection.
        /// </value>
        [DataMember()]
        public List<string> Removed
        {
            get
            {
                if (_eventArgsRemoved == null)
                {
                    _eventArgsRemoved = new List<string>();
                }
                return _eventArgsRemoved;
            }
        }
        private List<string> _eventArgsRemoved;
        #endregion
    }
}
